class BillManager:
    def __init__(self):
        self.incomes = []
        self.expenses = []
    def add_record(self, record_type, date, amount, category, remark):
        if amount <= 0:
            print(f"{record_type}金额必须为正数。")
            return
        record = {'date': date,'amount': amount,'category': category,'remark': remark
        }
        if record_type == '收入':
            self.incomes.append(record)
            print("收入记录成功。")
        elif record_type == '支出':
            self.expenses.append(record)
            print("支出记录成功。")
        else:
            print("记录类型错误。")
    def query_records(self, start_date=None, end_date=None, category=None):
        for record_type, records in [('收入', self.incomes), ('支出', self.expenses)]:
            print(f"{record_type}记录：")
            for record in records:
                if (not start_date or record['date'] >= start_date) and \
                        (not end_date or record['date'] <= end_date) and \
                        (not category or record['category'] == category):
                    print(
                        f"日期：{record['date']}, 金额：{record['amount']}, 类别：{record['category']}, 备注：{record['remark']}")
    def statistics(self):
        total_income = sum(r['amount'] for r in self.incomes)
        total_expense = sum(r['amount'] for r in self.expenses)
        balance = total_income - total_expense
        print(f"总收入：{total_income}, 总支出：{total_expense}, 余额：{balance}")
if __name__ == "__main__":
    manager = BillManager()
    manager.add_record('收入', '2024-10-01', 5000, '工资', '10月份工资')
    manager.add_record('支出', '2024-10-02', 1000, '餐饮', '外出就餐')
    manager.query_records(start_date='2024-10-01', end_date='2024-10-31')
    # 统计
    manager.statistics()
